package com.boardour.toupin.push;


import android.media.projection.MediaProjection;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author youjile
 * @CreateDate 2021/3/12
 * @Describe 消息观察者模式，状态改变后执行的操作
 */
public class ProjectionObservable {

    private List<ProjectionObserver> observers = new ArrayList<>();
    private static ProjectionObservable observable;

    private ProjectionObservable() {
    }

    public static ProjectionObservable getInstance() {
        if (observable == null) {
            observable = new ProjectionObservable();
        }
        return observable;
    }

    public void onChange(MediaProjection mediaProjection) {
        for (ProjectionObserver observer : observers) {
            observer.onChange(mediaProjection);
        }
    }

    public void register(ProjectionObserver observer) {
        observers.add(observer);
    }

    public void unregister(ProjectionObserver observer) {
        observers.remove(observer);
    }

}
